package com.sphd.restaurantsystem.model;


import com.android.volley.VolleyError;
import com.sphd.restaurantsystem.info.ManagerInfo;
import com.sphd.restaurantsystem.interfaces.VolleyJsonObjectCallBack;
import com.sphd.restaurantsystem.presenter.DianzhangPresenterImpl;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/11/08
 */

public class DianzhangModelImpl implements DianzhangModel, VolleyJsonObjectCallBack {
    DianzhangPresenterImpl dianzhangPresenter;

    @Override
    public void sendUrl(String url, DianzhangPresenterImpl dianzhangPresenter) {
        volleyUtil.setJsonObjectRequest(url, this);
        this.dianzhangPresenter = dianzhangPresenter;
    }

    @Override
    public void onResponse(JSONObject response) {
        try {
            List<ManagerInfo> managerInfos = JsonUtil.getListFromString(response.getString("res"), ManagerInfo.class);
            dianzhangPresenter.sendRes(managerInfos);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {
            dianzhangPresenter.sendError(error);
    }
}